class ProjectsController < ApplicationController

  def index
    @projects = params[:enterprise_id].blank? ? Project.all : Project.where(:enterprise_id => params[:enterprise_id])
  end

  def show
    @project = Project.find(params[:id])
  end

  def new
    @project = Project.new
  end

  def create
    @project = Project.new(params[:project])
    if @project.save
      flash[:success] = "• 『#{@project.name}』的基本资料保存成功!"
      redirect_to :action => :index
    else
      render :new 
    end
  end

  def edit
    @project = Project.find(params[:id])
  end

  def update
    @project = Project.find(params[:id])
    if @project.update_attributes(params[:project])
      flash[:success] = "• 『#{@project.name}』的基本资料更新成功!"
      redirect_to :action => :index
    else
      render :new 
    end
  end

  def destroy
    @project = Project.find(params[:id])
    @project.destroy
    flash[:success] = "• 『#{@project.name}』删除成功!"
    redirect_to :action => :index
  end
end
